package sostats.core.base;

import java.util.ArrayList;
import java.util.List;

import com.google.common.base.Function;
import com.google.common.collect.Lists;

public class QueryNode extends TableNode{
	public QueryNode(String name) {
		super(name);
	}
	List<Joint> children = new ArrayList<Joint>();
	public List<TableNode> getTableNode(){
		return Lists.transform(children, new Function<Joint,TableNode>(){
			@Override
			public TableNode apply(Joint input) {
				return (TableNode)input.getTarget();
			}
		});
	}
	public List<String> getJointValues(){
		return Lists.transform(children, new Function<Joint,String>(){
			@Override
			public String apply(Joint input) {
				return "join "+input.getTarget().getTableName()+
						" on "+input.getJoinedTable().getTableName()+"."+input.getFk()+
						" = "+input.getTarget()+"."+input.getPk();
			}
		});
	}
}
